package edu.hawaii.senin.iclouds.basics;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import org.junit.Before;
import org.junit.Test;

/**
 * Tests population that implements bury routines.
 * 
 * @author Pavel Senin
 * 
 */
public class TestBuryRoutines {

  private Specie atomH;

  private Specie moleculeH2O;

  private Specie moleculeCO;

  private PopulationWithBury pop;

  /**
   * A liitle fixture for the tests.
   * 
   * @throws Exception if error encountered.
   */
  @Before
  public void setUp() throws Exception {
    this.pop = new PopulationWithBury(1000L);
    this.atomH = new Atom("H", 1L);
    this.moleculeCO = new Molecule("CO", 3L);
    this.moleculeH2O = new Molecule("H2O", 7L);
  }

  /**
   * Tests basic routines.
   * 
   * @throws PopulationException if error encountered.
   */
  @Test
  public void testBasics() throws PopulationException {

    this.pop.addSpecie(this.atomH.getName(), true);
    assertTrue("testing contains", this.pop.surfaceContains(this.atomH.getName()));
    assertEquals("testing speciesNum", 1, this.pop.surfaceSpeciesNum());
    assertEquals("testing getSpecieVolume", 1L, 
        this.pop.totalSpecieVolume(this.atomH.getName()));
    assertEquals("testing getPopulationTotalSeize", 1L, this.pop.surfaceTotalSize());

    this.pop.addSpecie(this.moleculeCO.getName(), true);
    assertTrue("testing contains", this.pop.surfaceContains(this.moleculeCO.getName()));
    assertEquals("testing speciesNum", 2, this.pop.surfaceSpeciesNum());
    assertEquals("testing getSpecieVolume", 1L, this.pop.totalSpecieVolume(this.moleculeCO
        .getName()));
    assertEquals("testing getPopulationTotalSeize", 2L, this.pop.surfaceTotalSize());

    this.pop.surfaceGetSpecie(this.moleculeCO.getName()).incrementAccumulatorValue(998L);
    assertEquals("testing getSpecieVolume", 999L, this.pop.totalSpecieVolume(this.moleculeCO
        .getName()));
    assertEquals("testing getPopulationTotalSeize", 1000L, this.pop.surfaceTotalSize());

    this.pop.addSpecie(this.moleculeH2O.getName(), true);
    assertTrue("testing contains", this.pop.surfaceContains(this.moleculeH2O.getName()));
    assertEquals("testing speciesNum", 3, this.pop.surfaceSpeciesNum());
    assertEquals("testing speciesNum", 1, this.pop.buriedSpeciesNum());
    assertTrue("testing contains", this.pop.buriedContains(this.moleculeCO.getName()));
    assertEquals("testing getPopulationTotalSeize", 1000L, this.pop.surfaceTotalSize());
    assertEquals("testing getBuriedTotalSize", 1L, this.pop.buriedTotalSize());
    assertEquals("testing getBuriedTotalSize", 1, this.pop.buriedSpeciesNum());
    assertEquals("testing getTotalSize", 1001L, this.pop.totalTotalSize());
  }
}
